package com.qixin.modules.ea.service.impl;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.qixin.modules.ea.service.IEaFpService;
import com.qixin.modules.eaBasic.util.ChangeIdToNameUtil;
import com.qixin.modules.rzInvoice.entity.EaBill;
import com.qixin.modules.rzInvoice.entity.EaBillItem;
import com.qixin.modules.rzInvoice.entity.EaHolidayDays;
import com.qixin.modules.rzInvoice.entity.EaHotelbookspersond;
import com.qixin.modules.rzInvoice.mapper.EaBillItemMapper;
import com.qixin.modules.rzInvoice.mapper.EaBillMapper;
import com.qixin.modules.rzInvoice.mapper.EaHolidayDaysMapper;
import com.qixin.modules.rzInvoice.mapper.EaHotelbookspersondMapper;
import com.qixin.modules.rzInvoice.service.IEaBillService;
import com.qixin.modules.rzInvoice.vo.EaBillPage;
import org.apache.commons.lang3.StringUtils;
import org.apache.shiro.SecurityUtils;
import org.jeecg.common.system.vo.LoginUser;
import org.jeecg.common.util.DateFormatUtil;
import org.jeecg.common.util.EmptyUtil;
import org.jeecg.common.util.GetUrlUtil;
import org.jeecg.common.util.Uuid32Util;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.math.BigDecimal;
import java.util.*;

/**
 * @Author:wly
 * @Date:2021/9/9
 * @Describtion: 发票信息
 */
@Service
public class EaFpImpl implements IEaFpService {
    @Autowired
    private EaBillMapper eaBillMapper;
    @Autowired
    private IEaBillService iEaBillService;
    @Autowired
    private EaBillItemMapper eaBillItemMapper;
    @Autowired
    private EaHotelbookspersondMapper eaHotelbookspersondMapper;
    @Autowired
    private EaHolidayDaysMapper eaHolidayDaysMapper;
    @Autowired
    private ChangeIdToNameUtil changeIdToNameUtil;

    @Value(value = "${server.fileurl}")
    private String fileurl;

    //发票新增操作(包括发票信息主表,发票信息子表)
    @Override
    @Transactional
    public Map<String,Object> saveMain(EaBillPage eaBillPage) {
        //查询发票信息是否已存在,已存在直接返回
        Map<String, Object> columnMap = new HashMap<String, Object>();
        columnMap.put("number", eaBillPage.getNumber());  //发票号码
//        columnMap.put("type", eaBillPage.getType());  //发票类型
        List<EaBill> eaBillList = eaBillMapper.selectByMap(columnMap);
        if(eaBillList.size() == 0 || eaBillPage.getNumber().equals("")){
            List<EaBillItem> eaBillItemList = eaBillPage.getEaBillItemList();  //发票明细
            List<EaHotelbookspersond> eaHotelbookspersondsList = eaBillPage.getEaHotelbookspersondList();  //入住明细
            List<EaHolidayDays> eaHolidayDaysList = eaBillPage.getEaHolidayDaysList();  //休息日

            //如果bill_file中有http://localhost:9092/fybx-boot/aaa.png,要处理只保留文件名
            String billFile = eaBillPage.getBillFile() != null ? eaBillPage.getBillFile() : "";
            // update-begin-by wujinbiao 2022/3/23 15:49 for 上传文件路径如果有包含地址直接取文件名
            eaBillPage.setBillFile(billFile);
            String str = "";
            if (StringUtils.isNotBlank(billFile) && "http".equals(billFile.substring(0,4))){
                int i = billFile.indexOf("fybx-boot");
                str = billFile.substring(i+10,billFile.length());
                eaBillPage.setBillFile(str);
            }
            // update-end-by wujinbiao 2022/3/23 15:49 for 上传文件路径如果有包含地址直接取文件名

            //发票信息
            EaBill eaBill = new EaBill();
            BeanUtils.copyProperties(eaBillPage, eaBill);

            try {
                BigDecimal fare = !"".equals(EmptyUtil.checkNull(eaBill.getFare())) ? eaBill.getFare() : new BigDecimal(0);
                eaBill.setFare(fare);    //票价(航空运输电子客票行程单)
            }catch (Exception e){
                eaBill.setFare(new BigDecimal(0));    //票价(航空运输电子客票行程单)
            }
            try {
                BigDecimal fuelSurcharge = !"".equals(EmptyUtil.checkNull(eaBill.getFuelSurcharge())) ? eaBill.getFuelSurcharge() : new BigDecimal(0);
                eaBill.setFuelSurcharge(fuelSurcharge);    //燃油附加费(航空运输电子客票行程单)
            }catch (Exception e){
                eaBill.setFuelSurcharge(new BigDecimal(0));    //燃油附加费(航空运输电子客票行程单)
            }
            try {
                BigDecimal caacDevelopmentFund = !"".equals(EmptyUtil.checkNull(eaBill.getCaacDevelopmentFund())) ? eaBill.getCaacDevelopmentFund() : new BigDecimal(0);
                eaBill.setCaacDevelopmentFund(caacDevelopmentFund);    //民航发展基金(航空运输电子客票行程单)
            }catch (Exception e){
                eaBill.setCaacDevelopmentFund(new BigDecimal(0));    //民航发展基金(航空运输电子客票行程单)
            }
            try {
                BigDecimal insurance = !"".equals(EmptyUtil.checkNull(eaBill.getInsurance())) ? eaBill.getInsurance() : new BigDecimal(0);
                eaBill.setInsurance(insurance);    //保险费(航空运输电子客票行程单)
            }catch (Exception e){
                eaBill.setInsurance(new BigDecimal(0));    //保险费(航空运输电子客票行程单)
            }
            try {
                BigDecimal taxRate = !"".equals(EmptyUtil.checkNull(eaBill.getTaxRate())) ? eaBill.getTaxRate() : new BigDecimal(0);
                eaBill.setTaxRate(taxRate);    //税率
            }catch (Exception e){
                eaBill.setTaxRate(new BigDecimal(0));    //税率
            }

            eaBill.setId(Uuid32Util.getUUid());  //主键
            eaBill.setIsused("0");
            eaBill.setCurrencyId("1");   //货币

            //金额字段都要判空
            String pretaxAmount = EmptyUtil.checkNull(eaBill.getPretaxAmount());   //税前金额
            if(pretaxAmount.equals("")){
                eaBill.setPretaxAmount("0");
            }
            String total = eaBill.getTotal();   //价税合计（小写）
            if(total.equals("")){
                eaBill.setTotal("0");
            }
            String tax = eaBill.getTax();   //税额
            if(tax.equals("")){
                eaBill.setTax("0");
            }

            eaBillMapper.insert(eaBill);

            //发票明细保存
            if(eaBillItemList != null && eaBillItemList.size() > 0){
                for (EaBillItem eaBillItem : eaBillItemList){
                    eaBillItem.setPid(eaBill.getId());    //赋值父类id
                    eaBillItem.setId(Uuid32Util.getUUid());  //主键
                    eaBillItemMapper.insert(eaBillItem);
                }
            }

            //入住明细保存
            if(eaHotelbookspersondsList != null && eaHotelbookspersondsList.size() > 0){
                for (EaHotelbookspersond eaHotelbookspersond : eaHotelbookspersondsList){
                    eaHotelbookspersond.setPid(eaBill.getId());    //赋值父类id
                    eaHotelbookspersond.setId(Uuid32Util.getUUid());  //主键
                    eaHotelbookspersondMapper.insert(eaHotelbookspersond);
                }
            }

            //休息日保存
            if(eaHolidayDaysList != null && eaHolidayDaysList.size() > 0){
                for (EaHolidayDays eaHolidayDays : eaHolidayDaysList){
                    eaHolidayDays.setPid(eaBill.getId());    //赋值父类id
                    eaHolidayDays.setId(Uuid32Util.getUUid());  //主键
                    eaHolidayDaysMapper.insert(eaHolidayDays);
                }
            }

            Map<String,Object> result = new HashMap<String,Object>();
            result.put("code","0");  //0成功,-1失败
            result.put("message","发票录入成功!");
            result.put("id",eaBill.getId());
            return result;
        }else{
            Map<String,Object> result = new HashMap<String,Object>();
            result.put("code","-1");  //0成功,-1失败
            result.put("message","发票号码:" + eaBillPage.getNumber() + "不要重复录入!");
            return result;
        }
    }


    //查询发票信息列表
    @Override
    public Map<String,Object> list(Map<String,Object> map) {
        LoginUser loginUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
        String page = map.get("page") != null ? map.get("page").toString() : "1";
        String limit = map.get("limit") != null ? map.get("limit").toString() : "10";
        String keyword = map.get("keyword") != null ? map.get("keyword").toString() : "";
        String userid = map.get("userid") != null ? map.get("userid").toString() : "";   //用户id
        String isAll = map.get("isAll") != null ? map.get("isAll").toString() : "1";   //是否全部
        String type = map.get("type") != null ? map.get("type").toString() : "";   //发票类型
        String kind = map.get("kind") != null ? map.get("kind").toString() : "";   //消费类型
        String addId = map.get("addId") != null ? map.get("addId").toString() : "";   //要多查询出来的发票id
        String sysOrgCode = map.get("sysOrgCode") != null ? map.get("sysOrgCode").toString() : "";   //所属组织
        String ids = map.get("ids") != null ? map.get("ids").toString() : "";   // 明细行已选择的发票id
        String delIds = map.get("delIds") != null ? map.get("delIds").toString() : ""; // 被删除的发票

        if(isAll.equals("1")){
            // 查询所有单据时，获取登录用户id
            userid = loginUser.getId();
        }else{
            userid = loginUser.getPkPsndoc();
        }

        String keyword1 = "%" + keyword + "%";
        map.put("keyword",keyword1);
        map.put("page",(Integer.parseInt(page) -1) * Integer.parseInt(limit));
        map.put("limit",Integer.parseInt(limit));
        map.put("userid",userid);
        map.put("isAll",isAll);
        map.put("sysOrgCode",sysOrgCode);
        if(!type.equals("")){
            String[] types = type.split(",");
            map.put("type",types);
        }else{
            map.put("type",type);
        }
        if(!kind.equals("")){
            String[] kinds = kind.split(",");
            map.put("kind",kinds);
        }else{
            map.put("kind",kind);
        }
        if(!addId.equals("")){
            String[] addIds = addId.split(",");
            map.put("addId",addIds);
        }else{
            map.put("addId",addId);
        }
        String[] idList = ids.split(",");
        if(idList.length > 0){
            map.put("ids",idList);
        }

        List<EaBill> list = eaBillMapper.selectEaBills(map);

        // update-begin-by wujinbiao 2022/3/31 9:32 for
        List<String> strs = Arrays.asList(delIds.split(","));
        int size = 0;
        if(strs.size() > 0){
            List<EaBill> eaBills = eaBillMapper.selectDelBills(strs);
            size = eaBills.size();
            list.addAll(eaBills);
        }
        // update-end-by wujinbiao 2022/3/31 9:32 for

        int count = 0;
        map.put("page",0);
        map.put("limit",0);
        List<EaBill> list2 = eaBillMapper.selectEaBills(map);
        count = list2.size();
        Map<String,Object> returnMap = new HashMap<String,Object>();
        returnMap.put("records",list);
        returnMap.put("total",count + size);
        return returnMap;
    }

    //查询发票详情
    @Override
    public Map<String,Object> selectById(String id) {
        //根据发票类型,查询不同的发票信息列表
        List<EaBill> mapList = new ArrayList<EaBill>();

        Map<String,Object> queryWrapper = new HashMap<String,Object>();
        queryWrapper.put("id",id);  //发票id
        queryWrapper.put("page",0);
        queryWrapper.put("limit",0);
        List<EaBill> eaBillsList = eaBillMapper.selectEaBills(queryWrapper);
        Map<String,Object> returnMap = new HashMap<String,Object>();

        if(eaBillsList.size() > 0){
            for (EaBill eaBill : eaBillsList) {
                Map map = JSON.parseObject(JSON.toJSONString(eaBill, SerializerFeature.WriteMapNullValue), Map.class);

                //格式化时间
                Long date = map.get("date") != null ? Long.parseLong(map.get("date").toString()) : null;
                String datestr = DateFormatUtil.formatDateyyMMdd(date);
                map.put("date",datestr);

                //格式化时间
                Long travelStartDay = map.get("travelStartDay") != null ? Long.parseLong(map.get("travelStartDay").toString()) : null;
                String travelStartDayStr = DateFormatUtil.formatDateyyMMdd(travelStartDay);
                map.put("travelStartDay",travelStartDayStr);

                //格式化时间
                Long travelEndDay = map.get("travelEndDay") != null ? Long.parseLong(map.get("travelEndDay").toString()) : null;
                String travelEndDayStr = DateFormatUtil.formatDateyyMMdd(travelEndDay);
                map.put("travelEndDay",travelEndDayStr);

                //添加发票图片
                String billFile = map.get("billFile") != null ? map.get("billFile").toString() : "";
                List<Map<String,Object>> fileList = GetUrlUtil.getUrl(billFile,fileurl);

                //添加发票图片fileList
                map.put("fileList",fileList);

                //添加相应的发票明细
                Map<String, Object> columnMap2 = new HashMap<String, Object>();
                columnMap2.put("pid", eaBill.getId());
                List<EaBillItem> eaBillItemsList = eaBillItemMapper.selectByMap(columnMap2);
                List<Map<String,Object>> mapList2 = new ArrayList<Map<String,Object>>();
                if(eaBillItemsList.size() > 0){
                    for (EaBillItem eaBillItem: eaBillItemsList) {
                        BigDecimal tax = eaBillItem.getTax() != null ? eaBillItem.getTax() : new BigDecimal(0);    //税额
                        BigDecimal total = eaBillItem.getTotal() != null ? eaBillItem.getTotal() : new BigDecimal(0);   //金额
                        eaBillItem.setTotalAmount(total.add(tax));  //总金额
                        //获取飞机座位等级名称
                        String seat = eaBillItem.getClassName();
                        List<Map<String,Object>> seatList = getAirPlaneSeatName(seat);
                        if(seatList.size() > 0){
                            Map<String,Object> seatMap = seatList.get(0);
                            String seatName = seatMap.get("classNameName") != null ? seatMap.get("classNameName").toString() : "";  //座位名称
                            eaBillItem.setClassNameName(seatName);
                        }

                        Map map2 = JSON.parseObject(JSON.toJSONString(eaBillItem, SerializerFeature.WriteMapNullValue), Map.class);
                        mapList2.add(map2);
                    }
                }

                //将发票明细加到items节点
                map.put("eaBillItemList",mapList2);

                //添加相应的入住明细
                Map<String, Object> columnMap3 = new HashMap<String, Object>();
                columnMap3.put("pid", eaBill.getId());
                List<EaHotelbookspersond> eaHotelbookspersondList = eaHotelbookspersondMapper.selectHotelBooksPersonds(columnMap3);
                List<Map<String,Object>> mapList3 = new ArrayList<Map<String,Object>>();
                if(eaHotelbookspersondList.size() > 0){
                    for (EaHotelbookspersond eaHotelbookspersond: eaHotelbookspersondList) {
                        Map map3 = JSON.parseObject(JSON.toJSONString(eaHotelbookspersond, SerializerFeature.WriteMapNullValue), Map.class);
                        //格式化时间
                        Long startdate = map3.get("startdate") != null ? Long.parseLong(map3.get("startdate").toString()) : null;
                        String startdateStr = DateFormatUtil.formatDateyyMMdd(startdate);
                        map3.put("startdate",startdateStr);

                        //格式化时间
                        Long enddate = map3.get("enddate") != null ? Long.parseLong(map3.get("enddate").toString()) : null;
                        String enddateStr = DateFormatUtil.formatDateyyMMdd(enddate);
                        map3.put("enddate",enddateStr);

                        //入住人
                        String personnelid = eaHotelbookspersond.getPersonnelid();
                        String name = changeIdToNameUtil.getPsnNameById(personnelid);
                        map3.put("personnelidName",name);

                        // 任职信息主键
                        String psnjobId = eaHotelbookspersond.getPsnjobId();
                        map3.put("psnjobId",psnjobId);

                        mapList3.add(map3);
                    }
                }

                //将入住明细加到items节点
                map.put("eaHotelbookspersondList",mapList3);

                //添加相应的休息日明细
                Map<String, Object> columnMap4 = new HashMap<String, Object>();
                columnMap4.put("pid", eaBill.getId());
                List<EaHolidayDays> eaHolidayDaysList = eaHolidayDaysMapper.selectByMap(columnMap4);
                List<Map<String,Object>> mapList4 = new ArrayList<Map<String,Object>>();
                if(eaHolidayDaysList.size() > 0){
                    for (EaHolidayDays eaHolidayDays: eaHolidayDaysList) {
                        Map map4 = JSON.parseObject(JSON.toJSONString(eaHolidayDays, SerializerFeature.WriteMapNullValue), Map.class);
                        //格式化时间
                        Long startdate = map4.get("startdate") != null ? Long.parseLong(map4.get("startdate").toString()) : null;
                        String startdateStr = DateFormatUtil.formatDateyyMMdd(startdate);
                        map4.put("startdate",startdateStr);

                        //格式化时间
                        Long enddate = map4.get("enddate") != null ? Long.parseLong(map4.get("enddate").toString()) : null;
                        String enddateStr = DateFormatUtil.formatDateyyMMdd(enddate);
                        map4.put("enddate",enddateStr);

                        mapList4.add(map4);
                    }
                }

                //将休息日明细加到items节点
                map.put("eaHolidayDaysList",mapList4);
                returnMap = map;
            }
        }
        return returnMap;
    }

    //查询飞机座位名称
    private List<Map<String,Object>> getAirPlaneSeatName(String seat) {
        List<Map<String,Object>> list = eaBillItemMapper.getAirPlaneSeatName(seat);
        return list;
    }

    @Override
    @Transactional
    public Map<String,Object> delMain(String id) {
        Map<String,Object> returnMap = new HashMap<String,Object>();
        //判断发票是否已使用,已使用不允许删除
        EaBill eaBill = eaBillMapper.selectById(id);
        String isused = eaBill.getIsused();  //是否被使用,1为已使用
        if(isused.equals("1")){
            returnMap.put("code","-1");
            returnMap.put("message","发票号码:"+eaBill.getNumber() + "已被使用,不允许被删除!");
            return returnMap;
        }

        //删除发票
        eaBillMapper.deleteById(id);

        //删除发票子表
        Map<String, Object> columnMap = new HashMap<String, Object>();
        columnMap.put("pid", id);
        List<EaBillItem> eaBillItemsList = eaBillItemMapper.selectByMap(columnMap);
        if(eaBillItemsList.size() > 0){
            for (EaBillItem eaBillItem: eaBillItemsList) {
                eaBillItemMapper.deleteById(eaBillItem.getId());
            }
        }

        //删除入住明细
        Map<String, Object> columnMap2 = new HashMap<String, Object>();
        columnMap2.put("pid", eaBill.getId());
        eaHotelbookspersondMapper.deleteByMap(columnMap2);

        //删除休息日明细
        Map<String, Object> columnMap3 = new HashMap<String, Object>();
        columnMap3.put("pid", eaBill.getId());
        eaHolidayDaysMapper.deleteByMap(columnMap3);

        returnMap.put("code","0");
        returnMap.put("message","删除成功!");
        return returnMap;
    }

    @Override
    @Transactional
    public Map<String,Object> updateMain(EaBillPage eaBillPage) {
        Map<String,Object> returnMap = new HashMap<String,Object>();
        List<EaBillItem> eaBillItemList = eaBillPage.getEaBillItemList();  //发票明细
        List<EaHotelbookspersond> eaHotelbookspersondsList = eaBillPage.getEaHotelbookspersondList();  //入住明细
        List<EaHolidayDays> eaHolidayDaysList = eaBillPage.getEaHolidayDaysList();  //休息日

        //如果bill_file中有http://localhost:9092/fybx-boot/aaa.png,要处理只保留文件名
        String billFile = eaBillPage.getBillFile() != null ? eaBillPage.getBillFile().toString() : "";

        // update-begin-by wujinbiao 2022/3/23 15:49 for 上传文件路径如果有包含地址直接取文件名
        eaBillPage.setBillFile(billFile);
        String str = "";
        if (StringUtils.isNotBlank(billFile) && "http".equals(billFile.substring(0,4))){
            int i = billFile.indexOf("fybx-boot");
            str = billFile.substring(i+10,billFile.length());
            eaBillPage.setBillFile(str);
        }
        // update-end-by wujinbiao 2022/3/23 15:49 for 上传文件路径如果有包含地址直接取文件名

        //发票信息
        EaBill eaBill = new EaBill();
        BeanUtils.copyProperties(eaBillPage, eaBill);

        //查询发票信息是否已存在,已存在直接返回
        Map<String, Object> columnMap5 = new HashMap<String, Object>();
        columnMap5.put("number", eaBillPage.getNumber());  //发票号码
        columnMap5.put("type", eaBillPage.getType());  //发票类型
        List<EaBill> eaBillList = eaBillMapper.selectByMap(columnMap5);

        columnMap5.put("id", eaBillPage.getId());  //发票id
        List<EaBill> eaBillList2 = eaBillMapper.selectByMap(columnMap5);
        if(eaBillList.size() == 0 || (eaBillList2.size() == eaBillList.size()) || eaBillPage.getNumber().equals("")){
            //金额字段都要判空
            String pretaxAmount = EmptyUtil.checkNull(eaBill.getPretaxAmount());   //税前金额
            if(pretaxAmount.equals("")){
                eaBill.setPretaxAmount("0");
            }
            String total = eaBill.getTotal();   //价税合计（小写）
            if(total.equals("")){
                eaBill.setTotal("0");
            }
            String tax = eaBill.getTax();   //税额
            if(tax.equals("")){
                eaBill.setTax("0");
            }

            try {
                BigDecimal fare = !"".equals(EmptyUtil.checkNull(eaBill.getFare())) ? eaBill.getFare() : new BigDecimal(0);
                eaBill.setFare(fare);    //票价(航空运输电子客票行程单)
            }catch (Exception e){
                eaBill.setFare(new BigDecimal(0));    //票价(航空运输电子客票行程单)
            }
            try {
                BigDecimal fuelSurcharge = !"".equals(EmptyUtil.checkNull(eaBill.getFuelSurcharge())) ? eaBill.getFuelSurcharge() : new BigDecimal(0);
                eaBill.setFuelSurcharge(fuelSurcharge);    //燃油附加费(航空运输电子客票行程单)
            }catch (Exception e){
                eaBill.setFuelSurcharge(new BigDecimal(0));    //燃油附加费(航空运输电子客票行程单)
            }
            try {
                BigDecimal caacDevelopmentFund = !"".equals(EmptyUtil.checkNull(eaBill.getFuelSurcharge())) ? eaBill.getFuelSurcharge() : new BigDecimal(0);
                eaBill.setCaacDevelopmentFund(caacDevelopmentFund);    //民航发展基金(航空运输电子客票行程单)
            }catch (Exception e){
                eaBill.setCaacDevelopmentFund(new BigDecimal(0));    //民航发展基金(航空运输电子客票行程单)
            }
            try {
                BigDecimal insurance = !"".equals(EmptyUtil.checkNull(eaBill.getInsurance())) ? eaBill.getInsurance() : new BigDecimal(0);
                eaBill.setInsurance(insurance);    //保险费(航空运输电子客票行程单)
            }catch (Exception e){
                eaBill.setInsurance(new BigDecimal(0));    //保险费(航空运输电子客票行程单)
            }
            try {
                BigDecimal taxRate = !"".equals(EmptyUtil.checkNull(eaBill.getTaxRate())) ? eaBill.getTaxRate() : new BigDecimal(0);
                eaBill.setTaxRate(taxRate);    //税率
            }catch (Exception e){
                eaBill.setTaxRate(new BigDecimal(0));    //税率
            }

            eaBillMapper.updateById(eaBill);

            //清除发票子表
            Map<String, Object> columnMap = new HashMap<String, Object>();
            columnMap.put("pid", eaBill.getId());
            int code = eaBillItemMapper.deleteByMap(columnMap);

            //发票明细保存
            if(eaBillItemList != null && eaBillItemList.size() > 0){
                for (EaBillItem eaBillItem : eaBillItemList){
                    eaBillItem.setPid(eaBill.getId());    //赋值父类id
                    eaBillItem.setId(Uuid32Util.getUUid());  //主键
                    eaBillItemMapper.insert(eaBillItem);
                }
            }

            //清除入住明细表
            Map<String, Object> columnMap2 = new HashMap<String, Object>();
            columnMap2.put("pid", eaBill.getId());
            int code2 = eaHotelbookspersondMapper.deleteByMap(columnMap2);

            //入住明细保存
            if(eaHotelbookspersondsList != null && eaHotelbookspersondsList.size() > 0){
                for (EaHotelbookspersond eaHotelbookspersond : eaHotelbookspersondsList){
                    eaHotelbookspersond.setPid(eaBill.getId());    //赋值父类id
                    eaHotelbookspersond.setId(Uuid32Util.getUUid());  //主键
                    eaHotelbookspersondMapper.insert(eaHotelbookspersond);
                }
            }

            //清除休息日明细表
            Map<String, Object> columnMap3 = new HashMap<String, Object>();
            columnMap3.put("pid", eaBill.getId());
            int code3 = eaHolidayDaysMapper.deleteByMap(columnMap3);

            //休息日保存
            if(eaHolidayDaysList != null && eaHolidayDaysList.size() > 0){
                for (EaHolidayDays eaHolidayDays : eaHolidayDaysList){
                    eaHolidayDays.setPid(eaBill.getId());    //赋值父类id
                    eaHolidayDays.setId(Uuid32Util.getUUid());  //主键
                    eaHolidayDaysMapper.insert(eaHolidayDays);
                }
            }

            returnMap.put("message","编辑成功!");
            returnMap.put("code","0");
            returnMap.put("id",eaBill.getId());
            return returnMap;
        }else{
            Map<String,Object> result = new HashMap<String,Object>();
            result.put("code","-1");  //0成功,-1失败
            result.put("message","发票号码:" + eaBillPage.getNumber() + "不要重复录入!");
            return result;
        }
    }

}
